package model
{
	
	import manager.*;
	
	/**
	 * -- CampPx --
	 * @desc	proxy for manage camps
	 * @author	Aqua (built on 2011-11-25)
	 */
	public class CampPx extends BasePx
	{
		//-----------------//
		//     Publics     //
		//-----------------//
		
		/**************************************************************************
		 * -- init --
		 * @desc		initialize proxy
		 *************************************************************************/
		public override function init():void
		{
			_charaPx = ProxyMgr.instance.getProxy(CharacterPx.NAME) as CharacterPx;
			_campXML = XML(ResourceMgr.instance.getRes("xml_camps")).camp;
		}
		
		/**************************************************************************
		 * -- getCampXML --
		 * @desc		get xml of camp by index
		 * @param		(index) index of camp
		 * @return		xml of camp
		 *************************************************************************/
		public function getCampXML(index:int):XML
		{
			return _campXML[index];
		}
		
		/**************************************************************************
		 * -- chooseCamp --
		 * @desc		player choose a camp, then will be given 2 characters of
		 * 				this camp as default characters
		 * @param		(campIndex) index of the camp
		 *************************************************************************/
		public function chooseCamp(campIndex:int):void
		{
			var charaList:Array;
			var count:int;
			var index:int;
			var xml:XML;
			
			charaList = [];
			for each (xml in _campXML.default_characters[campIndex].id)
			{
				charaList.push(xml.toString());
			}
			
			count = charaList.length;
			index = int(Math.random() * count);
			_charaPx.createChara(charaList.splice(index, 1)[0]);
			index = int(Math.random() * (count - 1));
			_charaPx.createChara(charaList[index]);
		}
		
		
		public static const NAME:String = "CampPx";
		
		private var _charaPx	:CharacterPx;
		private var _campXML	:XMLList;
	}
	
}